<%@ include file="/WEB-INF/jsp/_include.jsp" %>

<t:base>
    <jsp:body>
    	<c:set var="editing" value= "${!empty competition}"/>
    	<c:set var="hasReferee" value= "${!empty referee}"/>
		<form action="s/competitions/save" method="post">
		<input type="hidden" name="key" value="${competition.key}" />
		<input type="hidden" name="refereeName" value= "${hasReferee? referee[0].name : ''}" />
		<input type="hidden" name="refereeKey" value= "${hasReferee? referee[0].key : ''}"/>
		<table>
			<tr>
				<td>Name: </td>
				<td><input type="text" name="name" value="${competition.name}" /></td>
			</tr>
			<tr>
				<td>Start Date:</td>
				<td><input type="text" name="startDate" placeholder="dd/mm/yyyy" value = '<fmt:formatDate pattern="dd/MM/yyyy" value="${competition.startDate}" />' /></td>
			</tr>
			<tr>
				<td>End Date:</td>
				<td><input type="text" name="endDate" placeholder="dd/mm/yyyy" value = '<fmt:formatDate pattern="dd/MM/yyyy" value="${competition.endDate}" />'/></td>
			</tr>
			<tr>
				<td>Location</td>
				<td><input type="text" name="location" value="${competition.location}" /></td>
			</tr>
			<tr>
				<td>Referee:</td>
				<td>
					<select id="sel-referee">
					    <c:forEach var="ref" items="${referee}">  
					        <option value="${ref.key}"  ${ref.key == competition.refereeKey ? 'selected': '' }>
					        	${ref.name}
					        </option>  
					    </c:forEach> 
					</select>
				</td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td><input type="submit" value="Submit" class="SubmitBtn"/></td>
			</tr>
		</table>
		</form>
		
		<script>
		$(function(){
			$('body').delegate("#sel-referee", "change" , function(e){
				var $selected = $(this);
				$("input[name=refereeName]").val($selected.find(":selected").text());
				$("input[name=refereeKey]").val($selected.val());
			});
		});

		
		</script>
    </jsp:body>
</t:base>